<template>
	<Modal v-model="modal"  title="邀请绑定" @on-ok="ok('form')"  :loading="loading">
		<IForm :model="form" ref="form" :rules="formRule">
			<FormItem prop="wechatNo" label="请输入需绑定的客服人员微信号" >
	            <IInput v-model="form.wechatNo" size="large" placeholder="请输入需绑定的客服人员微信号" />
	        </FormItem>
		</IForm>
	</Modal>
</template>
<script>
	import {Modal,Form,Input} from 'iview';

	export default{
		props :{
            callback:{
                type: Function,
                required : true,
            },
        },
		components:{
            Modal,
            'IInput' : Input,
			'IForm' : Form,
			'FormItem' : Form.Item,
        },
		data () {
			return {
                modal :false,
                loading : true,
                form:{
                	id : 0,
        			wechatNo:'',
        		},
        		formRule : {
	                wechatNo: [
	                    { required: true, message: '请填写微信号', trigger: 'blur' },
	                ],
	            },
            }
		},
		methods:{
			changeLoading(){
	            this.loading = false;
	            this.$nextTick(() => {
	              this.loading = true;
	            });
	        },
	        ok(name){
        		this.$refs[name].validate(valid => {
        			if (!valid) {this.changeLoading();return false;}
        			this.Axios.Wechat.Function.Customer.Invite(this.form)
		            .then(res =>{
		            	this.changeLoading();
		            	if(!res) return false;
		            	this.modal = false;
		            	this.callback();
		            })
        		})
        	},
		},
		watch:{
            modal:function(bool){
                if(!bool){
                	this.form.id = 0;
                	this.form.wechatNo = '';
                }
            },
        }
	}
</script>